package com.shqcjd.yunweiyanoperator.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.shqcjd.yunweiyanoperator.R;
import com.shqcjd.yunweiyanoperator.api.ApiService;
import com.shqcjd.yunweiyanoperator.helper.rxjavahelper.RxObserver;
import com.shqcjd.yunweiyanoperator.helper.rxjavahelper.RxSchedulersHelper;
import com.shqcjd.yunweiyanoperator.model.ResponseData;
import com.shqcjd.yunweiyanoperator.model.pojo.FileBean;
import com.shqcjd.yunweiyanoperator.ui.adapter.RemoteFileListAdapter;
import com.shqcjd.yunweiyanoperator.ui.base.BaseActivity;
import com.shqcjd.yunweiyanoperator.ui.base.BasePresenter;
import com.shqcjd.yunweiyanoperator.util.UIUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.disposables.Disposable;

/**
 * 远程指导记录的文件列表
 */
public class HistoryGuideFileActivity extends BaseActivity {

    @BindView(R.id.rv_file_list)
    RecyclerView rvFileList;
    @BindView(R.id.btn_finish)
    ImageView btnFinish;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    private RemoteFileListAdapter fileListAdapter;
    private View notDataView;
    private Context mContext;

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_history_guide_file;
    }

    @Override
    public void initView() {
        super.initView();
        mContext = this;
        notDataView = getLayoutInflater().inflate(R.layout.layout_no_data, (ViewGroup) rvFileList.getParent(), false);
        tvTitle.setText("文件列表");
        initAdapter();
    }

    private void initAdapter() {
        fileListAdapter = new RemoteFileListAdapter();
        rvFileList.setLayoutManager(new LinearLayoutManager(this));
        rvFileList.setAdapter(fileListAdapter);
        fileListAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                FileBean item = (FileBean) adapter.getItem(position);
                Intent intent = new Intent(mContext, UIUtils.previewClass(item.extension));
//                intent.putExtra("name", item.filename);
                intent.putExtra("url", item.url);
                startActivity(intent);
            }
        });
    }

    @Override
    public void initData() {
        getData();
    }

    private void getData() {
//        ApiService.getGuideFileList(guideID)
//                .compose(RxSchedulersHelper.io_main())
//                .subscribe(new RxObserver<ResponseData<List<FileBean>>>() {
//                    @Override
//                    public void _onSubscribe(Disposable d) {
//                        showWaitingDialog("获取数据中");
//                    }
//
//                    @Override
//                    public void _onNext(ResponseData<List<FileBean>> retData) {
//                        if (retData.retCode == 10000) {
//                            List<FileBean> data = retData.data;
//                            if (data.size() > 0) {
//                                fileListAdapter.setNewData(data);
//                            } else {
//                                fileListAdapter.setNewData(null);
//                                fileListAdapter.setEmptyView(notDataView);
//                            }
//                        }
//                    }
//
//                    @Override
//                    public void _onError(String errorMessage) {
//                        hideWaitingDialog();
//                    }
//
//                    @Override
//                    public void onComplete() {
//                        hideWaitingDialog();
//                    }
//                });
    }





    @OnClick(R.id.btn_finish)
    public void onViewClicked() {
        finish();
    }
}
